﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        //window.onscroll = function () {
        //    var div = document.getElementById("div");
        //    var scrollTop = document.body.scrollTop;
        //    alert(scrollTop);
        //    div.style.top = scrollTop + "px";
        //}

        //window.onscroll = function () {
        //    var oFix = document.getElementById("div");
        //    oFix.style.top = document.documentElement.scrollTop + "px";
        //}
        function getscrollTop() {
            return window.pageYOffset  //用于FF
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
        };
        window.onscroll = function () {
            var oFix = document.getElementById("div");
            oFix.style.top = getscrollTop() + "px";
        }
    </script>
</head>
<body style="height: 2000px">
    <div id="div" style="width: 100px; height: 100px; background: #CC0000; position: absolute;">
    </div>
</body>
</html>
